package code.structure.module.scene.view.iso.product.base
{
	import code.structure.manager.bitmap.MaterialBitmapCoverManager;
	import code.untils.SceneConfig;

	/**
	 * 多次生长 成熟后可能需要动画 (果树、种子继承C 刷新物 )
	 * @author Yuri
	 * 
	 */
	public class ProductedBIsoObject extends ProductIsoObject
	{
		
		private var _isHaveOnlyOneFrame:Boolean = true;
		
		/**
		 *当前第几帧 
		 */
		protected var _frame:int;
		public function ProductedBIsoObject()
		{
			super();
//			isNeedAnimation = false;
		}
		
		/**
		 * 
		 * 刷新生产信息 进行后续操作
		 */
		override protected function refreshProductData():void
		{
			if(data.growTimes<=0){
				if(parentWorld)
				parentWorld.removeFromWorld(this);
			}else{
				if(data.endTime<=0){
					if(isHaveWithered){
						checkIfWithered();
					}else{
						ripe();
					}
				}else{
					product();
				}
			}
		}	
		
		/**
		 *造好回调 
		 * 
		 */
		override public function initBuildCallFun():void{
			data.endTime = 0;
			data.growTimes = productShopItemData.productAttachData.growCount;
			data.status = 4;
			refreshProductData();
		}
		
		/**
		 *收获回调 
		 * 
		 */
		override public function harvestCallFun():void{
			super.harvestCallFun();
			data.growTimes -=1;
			data.endTime = productShopItemData.productAttachData.growTime; //重复生产 接着倒计时
			continuePrepareProduct();
		}
		
		/**
		 *继续准备生产 
		 * 
		 */
		protected function continuePrepareProduct():void{
			refreshProductData();
		}
		
		override protected function jumpInitStatus():void{
			jumpToFrame(1);
			if(_bitmapList && frameSumCount>0)
				verticalHeight = _bitmapList[0][1];
		}
		
		/**
		 *转到第二帧 
		 * 
		 */
		override protected function jumpProgressStatus():void{
			jumpToFrame(2);
			if(_bitmapList && frameSumCount>1)
				verticalHeight = _bitmapList[1][1];
		}
		
		/**
		 *成熟状态 
		 * 
		 */
		override protected function jumpMatureStatus():void{
			if(_bitmapList && frameSumCount>2)
				verticalHeight = _bitmapList[2][1];
			if(_ripeAnimationList.length>0){
				/*_mainPlayer.dataArray = _ripeAnimationList;
				_mainPlayer.goToAndPlay(1);
				addMotionListener();
				
				_isChangeFacade = true;*/
				onRipeAnamationCoverCompleteFun(_ripeAnimationList);
			}else{
				if(_bitmapList.length>4){
					MaterialBitmapCoverManager.getInstance().getMaterial(productShopItemData.sPath,SceneConfig.SCENE_MATURE_ANIMATION,onRipeAnamationCoverCompleteFun);
				}else{
					jumpToFrame(3);
				}
			}
		}
		
		override protected function jumpWitheredStatus():void{
			jumpToFrame(4);
			if(_bitmapList && frameSumCount>3)
				verticalHeight = _bitmapList[3][1];
		}
		
		 /**
		*跳帧 给不需要动画时候使用
		* @param frame
		* 
		*/
		override protected function jumpToFrame(frame:int):void{
			if(!isMaterialLoadComplete) return;
			if(isHaveOnlyOneFrame) frame = 1;
			
//			if(_frame == frame) return;
			_frame = frame;
			super.jumpToFrame(frame);
		}

		/**
		 *是否只有一帧的显示 不需要切换 
		 */
		public function get isHaveOnlyOneFrame():Boolean
		{
			return _isHaveOnlyOneFrame;
		}

		/**
		 * @private
		 */
		public function set isHaveOnlyOneFrame(value:Boolean):void
		{
			_isHaveOnlyOneFrame = value;
		}

		override public function set frameSumCount(value:int):void{
			if(value==1) isHaveOnlyOneFrame = true;
			super.frameSumCount = value;
		}

	}
}